package com.scorpio.web.controller.chatnotify;

import java.util.List;

import com.scorpio.chatnotify.domain.AutoGreetEntity;
import com.scorpio.chatnotify.service.IAutoGreetService;
import com.scorpio.common.core.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.scorpio.common.annotation.Log;
import com.scorpio.common.enums.BusinessType;
import com.scorpio.common.annotation.RepeatSubmit;
import com.scorpio.common.core.controller.BaseController;
import com.scorpio.common.core.domain.AjaxResult;
import com.scorpio.common.utils.poi.ExcelUtil;
import com.scorpio.common.utils.verification.AddGroup;
import com.scorpio.common.utils.verification.DefaultGroup;
import com.scorpio.common.utils.verification.UpdateGroup;

/**
 * 自动打招呼Controller
 *
 * @author scorpio
 * @date 2020-10-10
 */
@RestController
@RequestMapping("/chatnotify/autogreet")
public class AutoGreetController extends BaseController {

    @Autowired
    private IAutoGreetService service;

    /**
     * 查询自动打招呼列表
     */
    @PreAuthorize("@ss.hasPermi('chatnotify:autogreet:list')")
    @GetMapping("/list")
    public TableDataInfo list(AutoGreetEntity entity) {
        startPage();
        List<AutoGreetEntity> list = service.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出自动打招呼列表
     */
    @PreAuthorize("@ss.hasPermi('chatnotify:autogreet:export')")
    @Log(title = "自动打招呼", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AutoGreetEntity entity) {
        List<AutoGreetEntity> list = service.selectList(entity);
        ExcelUtil<AutoGreetEntity> util = new ExcelUtil<>(AutoGreetEntity.class);
        return util.exportExcel(list, "autogreet");
    }

    /**
     * 获取自动打招呼详细信息
     */
    @PreAuthorize("@ss.hasPermi('chatnotify:autogreet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(service.selectById(id));
    }

    /**
     * 新增自动打招呼
     */
    @PreAuthorize("@ss.hasPermi('chatnotify:autogreet:add')")
    @Log(title = "自动打招呼", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated(value = {DefaultGroup.class, AddGroup.class}) @RequestBody AutoGreetEntity entity) {
        return toAjax(service.save(entity));
    }

    /**
     * 修改自动打招呼
     */
    @PreAuthorize("@ss.hasPermi('chatnotify:autogreet:edit')")
    @Log(title = "自动打招呼", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated(value = {DefaultGroup.class, UpdateGroup.class}) @RequestBody AutoGreetEntity entity) {
        return toAjax(service.update(entity));
    }

    /**
     * 删除自动打招呼
     */
    @PreAuthorize("@ss.hasPermi('chatnotify:autogreet:remove')")
    @Log(title = "自动打招呼", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }
}
